# -*- coding: utf-8 -*-

 ###############################################
 ##                                             ##
 ##   Empresa Básica                             ##
 ##                                              ##
 ##                                              ##
 ##                                              ##
 ##   por Críptidos Digitales                    ##
 ##   GPL (c)2008                                ##
  ##                                             ##
    ###############################################

# print (0), "puntoVenta          begin"

from PyQt4 import QtCore, QtGui

import puntoVenta_ui

from cdWidgets import cdSlideFrame

# from ventas import manejador as manejadorVentas, igu as igVentas

# from ventas import Controlador as ControladorVentas


import ventas
# print (333), controladorVentas
# print dir(controladorVentas)

# print (0), "puntoVenta            definitions"


class Forma(QtGui.QFrame):

    @property
    def app(self):
        return self.__app

    @property
    def eventRouter(self):
        return self.__eventRouter

    @property
    def owner(self):
        return self.__owner


    def __init__(self, *args, **kwds):
        m = "puntoVenta.Forma.__init__()"
        # print (), m

        if kwds.has_key('app'):
            self.__app = kwds.pop('app')
        else:
            self.__app = None

        if kwds.has_key('content'):
            self.__content = kwds.pop('content')
        else:
            self.__content = None

        if 'eventRouter' in kwds.keys():
            self.__eventRouter = kwds.pop('eventRouter')
        else:
            self.__eventRouter = None

        if kwds.has_key('owner'):
            self.__owner = kwds.pop('owner')
        else:
            self.__owner = None

        QtGui.QFrame.__init__(self, *args)

        self.ui = puntoVenta_ui.Ui_Form()
        self.ui.setupUi(self)

        self.ui.tabWidget.clear()

        # self.ui.title.setText(u"MOSTRADOR")
        # self.ui.title.setStyleSheet("background-color:#A0A0FF")

        font = QtGui.QFont()
        font.setBold(True)
        font.setPointSize(9*self.app.fontZoom)

        self.ui.tabWidget.clear()
        self.ui.tabWidget.setFont(font)

        ## Ventas
        print 111
        self.app.setController('ventas', ventas.Controller(app=self.app, eventRouter= self.eventRouter))

        self.ui.ventas = self.app.controller('ventas').Form(self, modo='captura')

        self.ui.tabWidget.addTab(self.ui.ventas, u"&VENTA")



        # controladorVentas = ventas.Controlador(app=self.app, eventRouter=self.eventRouter)

        # self.ui.ventas = controladorVentas.(app=self.app)
        # self.ui.tabWidget.addTab(self.ui.ventas, u"&VENTA")

        # moduleVentas = controladorVentas.Controlador(self, parent=self, eventRouter=self.owner)

        # self.ui.ventas = igVentas.Forma(self, owner=self.owner, app=self.app, modo='captura')
        # self.ui.tabWidget.addTab(self.ui.ventas, u"&VENTA")
        # self.connect(self.ui.ventas, QtCore.SIGNAL('lugaresChanged()'), self.lugaresChanged)
        # self.connect(self.ui.ventas, QtCore.SIGNAL('clientesChanged()'), self.clientesChanged)
        # self.connect(self.ui.ventas, QtCore.SIGNAL('ventasChanged()'), self.ventasChanged)
        # self.connect(self.ui.ventas, QtCore.SIGNAL('addProduct()'), self.addProduct)

        ## Taller
        print 222
        if self.app.formacion == self.app.TALLER:
            from servicios import manejador as manejadorServicios, igu as igServicios
            self.ui.servicios = igServicios.Forma(self, owner=self.owner, app=self.app, modo='captura')
            self.ui.tabWidget.addTab(self.ui.servicios, u"&Servicio")
            self.connect(self.ui.servicios, QtCore.SIGNAL('serviciosChanged()'), self.serviciosChanged)
            self.connect(self.ui.servicios, QtCore.SIGNAL("equiposChanged()"), self.equiposChanged)

        if self.ui.tabWidget.count() == 1:
            self.ui.tabWidget.tabBar().hide()

        self.connect(self.owner, QtCore.SIGNAL('capturaPagoObligatoriaChanged'), self.capturaPagoObligatoriaChanged)
        self.connect(self.owner, QtCore.SIGNAL('clasificacionesChangedBroadcast()'), self.clasificacionesChangedBroadcast)
        self.connect(self.owner, QtCore.SIGNAL('clientesChangedBroadcast()'), self.clientesChangedBroadcast)
        self.connect(self.owner, QtCore.SIGNAL('empleadosChangedBroadcast()'), self.empleadosChangedBroadcast)
        self.connect(self.owner, QtCore.SIGNAL('lugaresChangedBroadcast()'), self.lugaresChangedBroadcast)
        self.connect(self.owner, QtCore.SIGNAL('rangosPrecioChangedBroadcast()'), self.rangosPrecioChangedBroadcast)


    def addProduct(self):
        self.owner.emit(QtCore.SIGNAL('addProduct()'))

    def capturaPagoObligatoriaChanged(self):    # print "puntoVenta.Forma.capturaPagoObligatoriaChanged()"
        self.emit(QtCore.SIGNAL('capturaPagoObligatoriaChanged'))

    def clasificacionesChangedBroadcast(self):
        self.emit(QtCore.SIGNAL('clasificacionesChangedBroadcast()'))

    def clientesChanged(self):                  # print "puntoVenta.Forma.clientesChanged()"
        self.emit(QtCore.SIGNAL("clientesChanged()"))

    def clientesChangedBroadcast(self):
        m = "puntoVenta.Forma.clientesChangedBroadcast()"

        self.emit(QtCore.SIGNAL("clientesChangedBroadcast()"))

    def empleadosChangedBroadcast(self):
        m = "puntoVenta.Forma.empleadosChangedBroadcast()"
        self.emit(QtCore.SIGNAL("empleadosChangedBroadcast()"))

    def equiposChanged(self):                   # print "puntoVenta.Forma.equiposChanged()"
        self.emit(QtCore.SIGNAL("equiposChanged()"))

    def lugaresChanged(self):                   # print "puntoVenta.Forma.lugaresChanged()"
        self.emit(QtCore.SIGNAL('lugaresChanged()'))

    def lugaresChangedBroadcast(self):          # print "puntoVenta.Forma.lugaresChangedBroadcast()"
        self.emit(QtCore.SIGNAL('lugaresChangedBroadcast()'))

    def rangosPrecioChangedBroadcast(self):     # print "puntoVenta.Forma.rangosPrecioChangedBroadcast()"
        self.emit(QtCore.SIGNAL('rangosPrecioChangedBroadcast()'))

    def serviciosChanged(self):
        self.emit(QtCore.SIGNAL('serviciosChanged()'))

    def ventasChanged(self):                    # print "puntoVenta.Forma.ventasChanged()"
        self.emit(QtCore.SIGNAL('ventasChanged()'))


# print (0), "puntoVenta          end"
